import { ElMessageBox, ElMessage } from 'element-plus'
import modal from '@/plugins/modal'

/**
 * 操作二次提示
 * 
 * @param {Function} api 操作接口api，必传
 * @param {Object} params 操作参数，必传
 * @param {String} opType 操作类型，必传
 * @param {String} content 提示信息，必传
 * 
 * @returns {Promise}
 */
export const useHandleConfirm = (
  api,
  params = {},
  opType,
  content
) => {
  return new Promise((resolve, reject) => {
    modal.confirm(`是否确定${content}?`).then(async () => {
      modal.loading('加载中...')
      const res = await api(params).finally(() => {
        modal.closeLoading()
      })
      if (!res) return reject(false)
      if (!res.msg) modal.msgSuccess(`${opType}成功!`)
      resolve(true)
    }).catch(() => {})
  })
}